home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / MiscKit1.7.1 / MiscKit / Palettes / MiscShell / MiscShell.subproj / MiscAwakeAction.m < prev    next >
Encoding:
Text File  |  1995-04-12  |  2.3 KB  |  115 lines

  1. // Copyright (C) 1995 Steve Hayman
  2. // Use is governed by the MiscKit license
  3.  
  4. #import "MiscAwakeAction.h"
  5. #import <apps/InterfaceBuilder.h>
  6. #define AWAKE_ACTION_VERSION 0
  7.  
  8. @implementation MiscAwakeAction
  9.  
  10. /*
  11.  * The meat of the class.  Send a message somewhere.
  12.  */
  13.  
  14. - fire
  15. {
  16.     if ( _target && action && [_target respondsTo:action] ) {
  17.     [_target perform:action with:self];
  18.     }    
  19.     return self;
  20. }
  21.  
  22. /*
  23.  * We get "awakeFromNib" when our nib file is loaded by a running
  24.  * application, after all the outlets are set up.
  25.  * Good time to fire the target/action.
  26.  */
  27. - awakeFromNib
  28. {
  29.     return [self fire];
  30. }
  31.  
  32. /*
  33.  * Bug in 3.1 and later: [NXApp isTestingInterface] always yields
  34.  * NO during read/write/awake.  Use this workaround.  See NeXTanswers
  35.  * #1525.  This idea is from FilenameList.m in the StringList miniexample
  36.  */
  37. - awake
  38. {
  39.     // test to see if mainMenu is visible, which it isn't while test
  40.     // interface mode is being set up. 
  41.     
  42.     if([NXApp conformsTo:@protocol(IB)]) {
  43.     if(! [[NXApp mainMenu] isVisible]) {
  44.         // main menu not visible, must be entering test mode
  45.         // (although this also happens when we are loading a .nib
  46.         //  at IB startup time, i.e. if you doubleclick on a .nib
  47.         //  and ib is opening it while starting up. no big deal.
  48.  
  49.         return [self perform:@selector(fire) with:nil 
  50.         afterDelay:1 cancelPrevious:YES];
  51.     }
  52.     }
  53.     return nil;
  54. }
  55.  
  56. - target
  57. {
  58.     return _target;
  59. }
  60. - setTarget:t
  61. {
  62.     _target = t;
  63.     return self;
  64. }
  65. - (SEL)action
  66. {
  67.     return action;
  68. }
  69. - setAction:(SEL)a
  70. {
  71.     action = a;
  72.     return self;
  73. }
  74.  
  75. - read:(NXTypedStream *)stream
  76. {
  77.     int version;
  78.  
  79.     [super read:stream];
  80.     version = NXTypedStreamClassVersion(stream, "MiscAwakeAction");
  81.     switch (version) {
  82.     case AWAKE_ACTION_VERSION:
  83.     NXReadTypes(stream, "@:", &_target, &action);
  84.     
  85.     if ( [NXApp respondsTo:@selector(isTestingInterface)]
  86.         && [NXApp isTestingInterface] ) {
  87.     
  88.  
  89.         [self perform:@selector(fire) with:nil afterDelay:1 
  90.         cancelPrevious:YES];
  91.     }
  92.  
  93.     break;
  94.     default:
  95.     NXLogError("[%s %s] - unknown version of %s in typed stream",
  96.         [[self class] name], sel_getName(_cmd), 
  97.         [[self class] name]);
  98.     break;
  99.     }
  100.     return self;
  101. }
  102.  
  103. - write:(NXTypedStream *)stream
  104. {
  105.     [super write:stream];
  106.     
  107.     NXWriteTypes(stream, "@:", &_target, &action);
  108.     
  109.     return self;
  110. }
  111.  
  112.  
  113. @end
  114.  
  115.